package edu.tgc.web.controller.code;

import org.abyss.common.web.controller.easyui.EasyuiResultBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.tgc.custom.EasyuiPageForm;
import edu.tgc.custom.EasyuiSort;
import edu.tgc.entity.code.TbCodeTaskState;
import edu.tgc.service.code.CodeService;

@Controller
@RequestMapping(value = "/code/taskState")
public class TaskStateController {
    @Autowired
    private CodeService service;

    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(Integer id) {
        this.service.deleteTaskstate(id);
        return EasyuiResultBuilder.buildAjaxResult("删除成功", true, true);
    }

    @RequestMapping(value = "/create")
    public String gotoCreate() {
        return "code/taskState/create";
    }

    @RequestMapping(value = "/manage")
    public String gotoManage() {
        return "code/taskState/manage";
    }

    @RequestMapping(value = "/update")
    public String gotoUpdate(Integer id, ModelMap map) {
        TbCodeTaskState taskState = this.service.findTaskStateById(id);
        map.put("model", taskState);
        return "code/taskState/create";
    }

    @ResponseBody
    @RequestMapping(value = "/page")
    public Object page(EasyuiPageForm pageForm, EasyuiSort easyuiSort) {
        PageRequest pageRequest = pageForm.buildPageRequest(easyuiSort.buildSort());
        Page<TbCodeTaskState> page = this.service.findTaskStatePage(pageRequest);
        return EasyuiResultBuilder.buildDataGridResult(page);
    }

    @ResponseBody
    @RequestMapping(value = "/save")
    public Object save(TbCodeTaskState taskState) {
        this.service.taskStateSave(taskState);
        return EasyuiResultBuilder.buildAjaxResult("保存成功", true, true);
    }
}
